# -*- coding: utf-8 -*-
# @Time: 2021/11/27 16:07
# @Author: lijinxi
# @File    : k_path_and_nbs.py
# @desc

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

mpl.rcParams["axes.unicode_minus"] = False

# 柱高信息
Y = [110, 228, 340, 466]
Y2 = [117, 238, 353, 476]
Y3 = [117, 239, 357, 483]
Y4 = [138, 288, 422, 557]

X = np.arange(len(Y))

bar_width = 0.2
tick_label = ['200', '400', '600', '800']

fig = plt.figure()
ax1 = fig.add_subplot(111)
axes = plt.gca()
axes.set_ylim([0, 800])
ax1.tick_params(labelsize=16)  # 刻度字体大小13
# 绘制柱状图
# p1=ax1.bar(X, Y, bar_width - 0.02, align="center", color="lightcoral",hatch='|')
p1 = ax1.bar(X, Y, bar_width - 0.04, align="center", color='white', edgecolor='lightcoral', hatch='\\\\')
p2 = ax1.bar(X + bar_width, Y2, bar_width - 0.04, color='white', edgecolor="sienna", align="center", hatch='//')
p3 = ax1.bar(X + bar_width * 2, Y3, bar_width - 0.04, color='white', edgecolor="darkcyan", align="center", hatch='++')
p4 = ax1.bar(X + bar_width * 3, Y4, bar_width - 0.04, color='white', edgecolor="deepskyblue", align="center",
             hatch='--')

ax = plt.gca()
ax.tick_params()
# ax.grid()
plt.xlabel("Number of Requests", fontsize=18)
plt.ylabel("Number of Accepted Requests", fontsize=18)
# plt.title()
plt.axhline(y=100, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=200, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=300, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=400, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=500, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=600, color='lightgray', ls=':', linewidth=1)
plt.axhline(y=700, color='lightgray', ls=':', linewidth=1)
plt.xticks(X + bar_width * 2, tick_label)
# 显示图例
# plt.legend(fontsize=14)
plt.legend([p1, p2, p3, p4], ['K=1', 'K=3', 'K=5', 'NBS'], fontsize=18, frameon=False, ncol=2, numpoints=2)
plt.savefig('accepted_requests.pdf', bbox_inches='tight')
plt.show()
